/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

// module
import Taro, { Component } from '@tarojs/taro';
import { AtInput } from 'taro-ui'

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton, CColumn } from '../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Toast} from '../../library/func';
import Icon from '../../project/style/icon';
import Http from '../../project/func/http/http';
import '../../library/style/patch.css';

// 引用组件
// import { Addcbtn, Editcunit } from '../../project/comp';

/******************************************************************************************
 * Export Class
 ******************************************************************************************/


export default class EditIndex extends Component {
	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			value:'',
			sort: ''
		}
	}
	
	/*------------------------------------------------------------------------------------
	* 声明周期
	*-----------------------------------------------------------------------------------*/
	componentDidMount(){
			
	}

    /*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/
	// onRedirect
	onRedirect(url){
		wx.redirectTo({
			url: url
		})
	}
	    
	// onNavigate
	onNavigate(url){
	    wx.navigateTo({
	        url: url
	    })
	}
	    
	//onNavigateBack
	onNavigateBack(num=1){
	     wx.navigateBack({
	        delta: num
	     })                    
	}

	changeValue = (type, e) =>{
		console.log(e)
		if(type == 'name'){
		this.setState({
			value: e
		})
		}
		if(type == 'sort'){
		this.setState({
			sort: e
		})
		}
	 }
	 
	//  提交分类
	onSubmit = ()=> {
		console.log(1313)
		Http.post({
			url: 'materialCate/logic/add.php',
			data:{
				fk_fid: 0,
				set_name : this.state.value,
				set_sort: this.state.sort
			},
			success: (data)=> {
				Toast.success('添加成功！')
				setTimeout(()=>{
					wx.navigateBack({
				        delta: 1
				     })
				},1500)
			}
		})
	}
	
	/**
	 * 渲染
	 */
	render() {
		return (
			<CPage>
				<CContent style='height:100vh;'>
                    <CBetween bg='#fff' pa='10'>
                        <CHand color='#cbb383' size='16' onClick={this.onNavigateBack}>取消</CHand>
                        <CHand color='#cbb383' size='16' onClick={this.onSubmit}>完成</CHand>
                    </CBetween>
					{/* 分类标题 */}
                    <CLine mt='15' ml='10' mb='4' size='15' color='#868686'>分类标题</CLine>
                    <AtInput
                        name='value'
                        type='text'
                        placeholder='请输入标题'
                        value={this.state.value}
                        onChange={this.changeValue.bind(this, 'name')}
                        class='atinputP15'
                        clear
                    />
					{/* 分类排序 */}
					<CLine mt='15' ml='10' mb='4' size='15' color='#868686'>分类排序</CLine>
                    <AtInput
                        name='value'
                        type='text'
                        placeholder='请输入排序'
                        value={this.state.sort}
                        onChange={this.changeValue.bind(this, 'sort')}
                        class='atinputP15'
                        clear
                    />

				</CContent>
			</CPage>
		);
	}
}

